###########################################################################################################################
# This code produces a full replication log file for "Fundraising Events and Non-Ideological Donation Motivations"
# EXCEPT FOR THE STATA .do file included at the same level as this code.
# The STATA file produces its own log file
###########################################################################################################################


list.of.packages <- c("here","dplyr", "Hmisc","tidyverse","hrbrthemes","scales","ggtext", "RColorBrewer", "viridis", "lubridate", "lfe", "gt","PanelMatch",
                      "Matrix", "zoo", "ineq", "reshape2", "tm", "data.table", "glmnet", "plm", "lmtest", "fixest", "fastLink", "stringr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

library(here)

here::i_am("LogFileProductionScript.R")



#create output folder if it does not exist yet 
if("Output"%in%list.files()==F){dir.create("Output")}

#divert output to log file
sink(file=here("Output", "Replication_log_file.txt"))

#run all code files
source(here("Scripts", "GoverningScript.R"),echo=T,max.deparse.length=Inf)

#close log file
sink()

